package HuaweiOD;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class 猜密码 {
    static int[] nums;
    static int level;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        nums = Arrays.stream(in.nextLine().split(",")).mapToInt(Integer::parseInt).toArray();
        level = Integer.parseInt(in.nextLine());
//        Arrays.stream(nums).forEach(System.out::println);
//        System.out.println(level);
        System.out.println(solve());
    }
    
    public static String solve(){
        Arrays.sort(nums);

        ArrayList<String> res = new ArrayList<>();
        dfs(res, new LinkedList<>(), 0);
        
        if (res.size() > 0){
            res.sort(String::compareTo);
            return String.join("\n", res);
        }
        return "None";
    }
    
    public static void dfs(ArrayList<String> res, LinkedList<String> path, int index){
        if (path.size() >= level){
            res.add(String.join(",", path));
        }
        for (int i = index; i < nums.length; i++) {
            if (i > 0 && nums[i] == nums[i - 1]){
                continue;
            }
            path.add(nums[i] + "");
            dfs(res, path, i + 1);
            path.removeLast();
        }
    }
}
